Dart.PowerTCP.EmailValidation Namespace > SegmentedStream Class > BeginRead Method : BeginRead(Byte[],Int32,Int32,AsyncCallback,Object) Method |
Begins an asynchronous read from the stream that complete when at least one byte is read. This operation reads at most count bytes.
[Visual Basic]
Overloads Overrides Public Function BeginRead( _
ByVal buffer() As Byte, _
ByVal offset As Integer, _
ByVal count As Integer, _
ByVal callback As AsyncCallback, _
ByVal state As Object _
) As IAsyncResult
[C#]
public override IAsyncResult BeginRead(
byte[] buffer,
int offset,
int count,
AsyncCallback callback,
object state
);
[C++]
public: IAsyncResult* BeginRead(
byte[]* buffer,
int offset,
int count,
AsyncCallback* callback,
Object* state
) override
[C++/CLI]
public:
IAsyncResult^ BeginRead(
bytearray<buffer>^ buffer,
int offset,
int count,
AsyncCallback^ callback,
Object^ state
) override
An IAsyncResult representing the asynchronous operation. To determine how many bytes were read, you must pass this IAsyncResult to the EndRead method of the stream. This should be done within your AsyncCallback event handler.
Exception | Description |
---|---|
IOException | Thrown when the stream is not Readable. |
ArgumentNullException | Thrown when the buffer or callback is null. |
ArgumentOutOfRangeException | Thrown when the offset is less than zero or when count is less than or equal to zero. |
ArgumentException | Thrown when the (offset + count) > buffer.Length. |
This is the standard method to use when reading a stream asynchronously. If a fixed-length record buffer is being read, use the overloaded Read() method that includes the 'bool fill' parameter. If a variable-length record segment is being read, use the overloaded Read() method that includes the 'byte[] delimiter' parameter.
The following example demonstrates asynchronously reading from the server using the stream interface. This involves creating a callback method in which the response is handled. If you would like to use fully asynchronous methods with events already implemented, try the low-level interface (Tcp.BeginRead & Tcp.BeginWrite).
[C#]
private void AsynchronousReadTest()
{
// Connect to the server
tcp1.Connect("atropos", 13);
// DAYTIME protocol (port 13) sends data and closes, receive data.
// This demonstrates receiving data asynchronously using the stream interface.
// data buffer is a global variable
databuffer = new byte[tcp1.ReceiveBufferSize];
// Begin the asynchronous Read operation.
tcp1.Stream.BeginRead(databuffer, 0, tcp1.ReceiveBufferSize, new System.AsyncCallback(MyCallback), null);
}
private void MyCallback(System.IAsyncResult ar)
{
// End pending asynchronous request.
if(ar.IsCompleted)
tcp1.Stream.EndRead(ar);
// Write result
Debug.WriteLine(System.Text.Encoding.Default.GetString(databuffer));
}
Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista
SegmentedStream Class | SegmentedStream Members | Overload List
Send comments on this topic.
Documentation version 1.0.3.0.
© 2008 Dart Communications. All rights reserved.